package com.blackcat.metaannotation.repeatable;

import java.lang.reflect.Method;

/**
 * <p> 描述 : 测试
 * @author : blackcat
 * @date  : 2020/8/7 10:38
*/
@Schedule(dayOfMonth="2月")
@Schedule(dayOfWeek="2周", hour=24)
public class TestRepetableAnnotation {

	@Schedule(dayOfMonth="3月")
	@Schedule(dayOfWeek="3周", hour=23)
	public void doPeriodicCleanup(){}

	public static void main(String[] args) throws NoSuchMethodException {
		Method doPeriodicCleanup = TestRepetableAnnotation.class.getMethod("doPeriodicCleanup");

		Schedules schedules = doPeriodicCleanup.getAnnotation(Schedules.class);
		System.out.println("获取标记方法上的重复注解：");
		for (Schedule schedule: schedules.value()){
			System.out.println(schedule);
		}

		System.out.println("获取标记类上的重复注解：");
		if (TestRepetableAnnotation.class.isAnnotationPresent(Schedules.class)){
			schedules = TestRepetableAnnotation.class.getAnnotation(Schedules.class);
			for (Schedule schedule: schedules.value()){
				System.out.println(schedule);
			}
		}
	}
}
